<include file="public@header"/>
</head>
<body>
<div class="lyear-layout-web">
    <div class="lyear-layout-container">
        <!--页面主要内容-->
        <main class="lyear-layout-content">
          
            <div class="container-fluid">
            
                <div class="row">
                   <div class="col-md-12">
                        <div class="card">
                            <ul class="nav nav-tabs">
                                <li><a href="{:url('NavMenu/index',['nav_id'=>$nav_id])}">导航菜单</a></li>
                                <li><a href="{:url('NavMenu/add',['nav_id'=>$nav_id])}">{:lang('ADMIN_MENU_ADD')}</a>
                                </li>
                                <li class="active"><a>{:lang('ADMIN_MENU_EDIT')}</a></li>
                            </ul>
                            <div class="card-body">
                                <form method="post" class="form-horizontal js-ajax-form margin-top-20" action="{:url('NavMenu/editPost')}">
                                    <fieldset>
                                        <div class="form-group">
                                            <label class="col-sm-2 control-label">上级:</label>
                                            <div class="col-md-6 col-sm-10">
                                                <select name="parent_id" class="form-control">
                                                    <option value="0">/</option>
                                                    {$nav_trees}
                                                </select>
                                            </div>
                                        </div>
                                        <div class="form-group form-inline">
                                            <label class="col-sm-2 control-label"><span class="form-required">*</span>地址:</label>
                                            <div class="col-md-6 col-sm-10">
                                                <input type="radio" id="external-link-radio">
                                                <input type="text" class="form-control" name="href" id="external-link-input">
                                                <input type="radio" id="select-href-radio">
                                                <select name="href" id="select-href" class="form-control">
                                                    <option value="{:base64_encode('home')}" data-name="首页">首页</option>
                                                    <foreach name="navs" item="vo">
                                                        <optgroup label="{$vo.name}">
                                                            {$vo.html}
                                                        </optgroup>
                                                    </foreach>
                                                </select>
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-sm-2 control-label"><span class="form-required">*</span>菜单名称:</label>
                                            <div class="col-md-6 col-sm-10">
                                                <input type="text" class="form-control" name="name" id="name-input" value="{$name}">
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-sm-2 control-label">打开方式:</label>
                                            <div class="col-md-6 col-sm-10">
                                                <select name="target" class="form-control">
                                                    <option value="">默认方式</option>
                                                    <option {$target=='_blank'?'selected':''} value="_blank">新窗口打开</option>
                                                </select>
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-sm-2 control-label">图标:</label>
                                            <div class="col-md-6 col-sm-10">
                                                <input type="text" class="form-control" name="icon" value="{$icon}">
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-sm-2 control-label">显示:</label>
                                            <div class="col-md-6 col-sm-10">
                                                <select name="status" class="form-control">
                                                    <option value="1">显示</option>
                                                    <php>$status_selected=empty($status)?"selected":"";</php>
                                                    <option value="0" {$status_selected}>隐藏</option>
                                                </select>
                                            </div>
                                        </div>
                                    </fieldset>
                                    <div class="form-group">
                                        <div class="col-sm-offset-2 col-sm-10">
                                            <input type="hidden" name="id" value="{$id}">
                                            <input type="hidden" name="nav_id" value="{$nav_id}">
                                            <button type="submit" class="btn btn-primary js-ajax-submit">{:lang("SAVE")}</button>
                                            <a class="btn btn-default" href="{:url('NavMenu/index',['nav_id'=>$nav_id])}">返回</a>
                                        </div>
                                    </div>
                                </form>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </main>
    </div>
</div>
<script src="__TMPL__/public/assets/js/admin.js"></script>
<script>
    $(function () {
        $("#select-href,#select-href-radio").click(function () {
            checkChange(2);
        });

        $("#select-href").change(function () {
            var $this = $(this);
            var label = $this.find("option[value='" + $this.val() + "']").data('name');
            $('#name-input').val(label);
        });

        $("#external-link-input,#external-link-radio").click(function () {
            checkChange(1);
        });

        var opt = $("#select-href option[value='" + '{$href}' + "']");
        if (opt.length > 0) {
            opt.prop('selected', true);
            checkChange(2);
        } else {
            checkChange(1);
            $('#external-link-input').val('{$href}');
        }

        function checkChange(i) {
            if (i == 1) {
                //自动输入url
                $('#external-link-input').attr('name', 'external_href');
                $('#select-href').removeAttr('name');
                $('#select-href-radio').prop('checked', false);
                $('#external-link-radio').prop('checked', true);
            } else {
                //选择链接url
                $('#select-href').attr('name', 'href');
                $('#external-link-input').removeAttr('name');
                $('#select-href-radio').prop('checked', true);
                $('#external-link-radio').prop('checked', false);
            }
        }
    });
</script>
</body>
</html>